<?php

namespace App\Http\Requests;

use App\Models\Topic;
use App\Rules\TuWenContent;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

class TopicRequest extends BaseRequest
{

    public function routeRules(): array
    {
        return [
            'api.topic.store|api.topic.update' => [
                'type' => ["required", Rule::in(array_keys(Topic::$types))],
                'fid' => 'required|exists:forums,id',
                'content_detail' => ['required', new TuWenContent()],
                'content_hide' => ['required_if:has_hide,1', new TuWenContent()],
            ],
            'admin.topic.sensitivity.change' => [
                'tid' => 'required|integer',
                'sensitivity' => 'required|integer|min:1',
            ],
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return $this->getRouteRules();
    }

    public function attributes()
    {
        return [
            'sensitivity' => '敏感度',
            'content_detail' => '正文内容',
            'content_hide' => '隐藏内容',
        ];
    }

}
